package com.gdit.zax.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.gdit.zax.dao.SearchDao;
import com.gdit.zax.entitys.SearchM;
import com.gdit.zax.factory.DAOFactory;
import com.gdit.zax.utils.DBUtil;
import com.gdit.zax.utils.O;
import com.gdit.zax.utils.TextUtil;
import com.gdit.zax.utils.VeriFicUtil;

public class GetHotSearch extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}
	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		//检测参数
		
		//检测连接、用户
		Connection conn = DBUtil.getConnection();
		
		if (conn==null) {
			O.printFail(response, 1000, "数据库连接失败!");
			return;
		}
		
		//开始
		DAOFactory dao = DAOFactory.init(conn, request, response);
		SearchDao sdao = dao.getSearchDao();
		ArrayList<SearchM> list = sdao.listHotSearchVideo(1, 10);
		ArrayList<Map<String, Object>> out = new ArrayList<Map<String,Object>>();
		for (SearchM searchM : list) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("text", searchM.getContent());
			map.put("id", searchM.getId());
			map.put("times", searchM.getCount());
			out.add(map);
		}
		O.printSuccess(response, out);
		
		
	}

}
